package org.springframework.boot.tests.hibernate52.mytest.beanpostprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.stereotype.Component;

@Component
public class InstantiationAwareBeanPostProcessorTest
		implements InstantiationAwareBeanPostProcessor {

	@Override
	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName)
			throws BeansException {
		if (beanClass == MyBeanPostProcessorTest.class) {
			Enhancer enhancer = new Enhancer();
			enhancer.setSuperclass(beanClass);
			enhancer.setCallback(new MyMethodInterceptor());
			MyBeanPostProcessorTest myMethodInterceptor = (MyBeanPostProcessorTest) enhancer
					.create();
			myMethodInterceptor.myBeanPostMethod();
			return myMethodInterceptor;
		}
		return null;
	}

}
